package logic

import (
	"2210a/vipshop/vipshoprpc/vipshoprpc"
	"context"

	"2210a/vipshop/vipshopapi/internal/svc"
	"2210a/vipshop/vipshopapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
	return &UpdatePasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePasswordLogic) UpdatePassword(req *types.UpdatePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.VipshopRpc.UpdatePassword(l.ctx, &vipshoprpc.UpdatePasswordRequest{
		Mobile:      req.Mobile,
		Password:    req.Password,
		OldPassword: req.OldPassword,
		NewPassword: req.NewPassword,
		Captcha:     req.Captcha,
		Code:        req.Code,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改密码成功",
		Data:    update.Id,
	}, nil
	return
}
